package io.renren.common.utils;

import com.google.common.base.Splitter;

import java.util.Map;
import java.util.regex.Matcher;
import java.util.regex.Pattern;

/**
 * @author: Mr.Wang
 * @description:
 * @create: $ $
 **/
public class UriUtil {

    /**
     * 获取指定url中的某个参数
     * @param url
     * @param name
     * @return
     */
    public static String getParamByUrl(String url, String name) {
        String params = url.substring(url.indexOf("?") + 1, url.length());
        Map<String, String> split = Splitter.on("&").withKeyValueSeparator("=").split(params);
        return split.get(name);
    }

    public static String getParamByRemark(String remark,String name){
        //您的公司名称:济南晨冠环保设备/您的意向展品:水处理设备/
        String last = remark.substring(remark.length()-1);
        if("/".equals(last)){
            remark = remark.substring(0,remark.length()-1);
        }
        System.out.println(remark);
        Map<String, String> split = Splitter.on("/").withKeyValueSeparator(":").split(remark);
        return split.get(name);
    }

    public static void main(String[] args) throws Exception {
        // Map<String, Object> param = new HashMap<>();
        // param.put("id", 1);
        // param.put("age", 18);
        // System.out.println(appendUrl("http://test.com", param));
        // System.out.println(appendUrl("http://test.com?name=a", param));
        //String url = "http://test.com?name=abd&id=1&age=18";
        //String url = "tid=1&startTime=2019-04-01&endTime=2019-05-11";
        //System.out.println(getParamByUrl(url, "startTime"));

        String remark = "您的公司名称:济南晨冠环保设备/您的意向展品:水处理设备";
        System.out.println(getParamByRemark(remark, "您的意向展品"));
    }

}
